#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> split(string str, string pattern)
{
    string::size_type pos;
    vector<string> result;
    str += pattern;
    int size = str.size();
    for (int i = 0; i < size; i++)
    {
        pos = str.find(pattern, i);
        if (pos < size)
        {
            result.push_back(str.substr(i, pos - i));
            i = pos + pattern.size() - 1;
        }
    }
    return result;
}
bool startWith(string s, string sub)
{
    return s.find(sub) == 0;
}

bool endWith(string s, string sub)
{
    return s.rfind(sub) == (s.length() - sub.length());
}
void printVector(vector<string> &ans)
{
    for (string a : ans)
    {
        cout << a << ",";
    }
    cout << endl;
}
int main()
{
    string str = "I am a worker!";
    vector<string> ans = split(str, " ");
    printVector(ans);
    return 0;
}
